#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

int find(vector<int> &f, int x)
{
        return f[x] == x ? x : f[x] = find(f, f[x]);
}

int issame(vector<int> &f, int x, int y)
{
        return find(f, x) == find(f, y);
}

void merge(vector<int> &f, int x, int y)
{
        int fx = find(f, x);
        int fy = find(f, y);
        f[fx] = fy;
}

int main()
{
        int n, m;
        cin >> n >> m;
        vector<int> father(n + 1, 0);
        iota(father.begin(), father.end(), 0);

        int op, x, y;
        for(int i = 0; i < m; i++){
                cin >> op >> x >> y;
                if(op == 2){
                        cout << (issame(father, x, y) ? "Y" : "N") <<endl;
                }else{
                        merge(father, x, y);
                }
        }
        return 0;
}